#include "wallpaperview.h"
#include <QGraphicsPixmapItem>
#include "toolkit.h"
#include <QLocale>
#include <QMouseEvent>

enum WallBtn
{
    CROSS_WB,
    POR_WB,
    NULL_WB,
}Wallbtn(NULL_WB);

WallpaperView::WallpaperView(QWidget *parent) :
    QGraphicsView(parent)
{
    m_Scene = new QGraphicsScene(this);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setScene(m_Scene);
    m_Scene->setSceneRect(0.0, 0.0, 640.0, 360.0);
    setGeometry(0.0,0.0,640.0,360.0);

    m_bgItem = m_Scene->addPixmap(QPixmap(":/image/wallpaper/bg.png"));
    m_bgItem->setZValue(0.0);

    switch(ToolKit::m_language)
    {
    case QLocale::Chinese:
    {
       m_CrosswiseItem = m_Scene->addPixmap(QPixmap(":/image/wallpaper/hf.png"));
       m_PortraitItem = m_Scene->addPixmap(QPixmap(":/image/wallpaper/sch.png"));
    }
    break;
    case QLocale::HongKong:
    case QLocale::Taiwan:
    {
        m_CrosswiseItem = m_Scene->addPixmap(QPixmap(":/image/wallpaper/hf.png"));
        m_PortraitItem = m_Scene->addPixmap(QPixmap(":/image/wallpaper/sf.png"));
    }
        break;
    default:
    {
        m_CrosswiseItem = m_Scene->addPixmap(QPixmap(":/image/wallpaper/h_144,106.png","png"));
        m_PortraitItem = m_Scene->addPixmap(QPixmap(":/image/wallpaper/s_330,106.png"));
    }
        break;
    }

    m_CrosswiseItem->setZValue(1.0);
    m_CrosswiseItem->setPos(144.0,106.0);

    m_PortraitItem->setZValue(1.0);
    m_PortraitItem->setPos(330.0,106.0);
}

void WallpaperView::mousePressEvent(QMouseEvent *event)
{
    if(QRectF(144.0,106.0,145.0,128.0).contains(event->pos()))
    {
        m_CrosswiseItem->setPos(149,110);
        Wallbtn = CROSS_WB;
    }
    else if(QRectF(330.0,106.0,145.0,128.0).contains(event->pos()))
    {
        m_PortraitItem->setPos(335,110);
        Wallbtn = POR_WB;
    }
    else
    {
        Wallbtn = NULL_WB;
    }
}

void WallpaperView::mouseReleaseEvent(QMouseEvent *event)
{
    switch(Wallbtn)
    {
    case CROSS_WB:
    {
        m_CrosswiseItem->setPos(144.0,106.0);
        if(QRectF(144.0,106.0,145.0,128.0).contains(event->pos()))
        {
            back(1);
        }
    }
    break;
    case POR_WB:
    {
        m_PortraitItem->setPos(330.0,106.0);
        if(QRectF(330.0,106.0,145.0,128.0).contains(event->pos()))
        {
            back(0);
        }
    }
    break;
    default:
        break;
    }
}
